package org.bongo.open.cumulo.arbitrator.distribute;

import org.bongo.open.cumulo.core.context.CumuloContext;
import org.bongo.open.cumulo.core.context.CumuloContextKeys;
import org.bongo.open.cumulo.core.message.MessageDistributable;

public class HashMessageDistributor extends MessageDistributorBase<Object> {

	@Override
	protected int distributeIndex(MessageDistributable<Object> distributable, CumuloContext context) {
		
		Object[] keys = distributable.getDistributionKeys();
		int hashCode = 0;
		int prime = 31;
		
		if(keys != null)
			for(Object key : keys) {
				hashCode = key.hashCode() + hashCode * prime;
			}
		
		// TODO - setup contexts
		//int maxSlots = Integer.parseInt(context.getContextValue(CumuloContextKeys.MAX_MSG_SLOTS_TO_DISTRIBUTE));
		int maxSlots = 1;
		return hashCode % maxSlots;
	}


}
